/*
 * Created on 25.06.2006 by leck
 *
 */
package de.devisnik.eidle.flashlight;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.contexts.IContextActivation;
import org.eclipse.ui.contexts.IContextService;

import de.devisnik.eidle.picture.FileUtils;
import de.devisnik.eidle.picture.MultiImageScreen;
import de.devisnik.eidle.screen.IScreen;
import de.devisnik.eidle.util.ScreenUtils;

public class MultiFlashlightScreen extends MultiImageScreen {

	private IContextActivation itsContext;

	public MultiFlashlightScreen() {
		super("Flashlight");
	}

	private int getPresentationTime() {
		return FlashlightPreferences.getPresentationTime() * 1000;
	}

	// @Override
	protected IScreen createPictureScreen(final Composite parent,
			final ImageDescriptor descriptor) {
		final FlashlightScreen screen = new FlashlightScreen(descriptor,
				getPresentationTime());
		return screen;
	}

	public ImageDescriptor[] createImageDescriptors() {
		if (FlashlightPreferences.isUseScreenShot()) {
			return new ImageDescriptor[] { ImageDescriptor
					.createFromImage(ScreenUtils.getScreenImage()) };
		}
		return FileUtils.getImagesInDirectory(FlashlightPreferences
				.getGlobalImagePath());
	}

	public void bigger() {
		FlashlightScreen screen = (FlashlightScreen) getCurrentScreen();
		screen.bigger();
	}
	
	public void smaller() {
		FlashlightScreen screen = (FlashlightScreen) getCurrentScreen();
		screen.smaller();		
	}

	public void left() {
		FlashlightScreen screen = (FlashlightScreen) getCurrentScreen();
		screen.turnLeft();				
	}
	
	public void right() {
		FlashlightScreen screen = (FlashlightScreen) getCurrentScreen();
		screen.turnRight();		
	}
	@Override
	public void createControl(Composite parent) {
		IContextService contextService = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class);
		itsContext = contextService.activateContext("de.devisnik.eidle.flashlight.context");
		super.createControl(parent);
	}
	
	@Override
	public void disposeControl() {
		super.disposeControl();
		IContextService contextService = (IContextService) PlatformUI.getWorkbench().getService(IContextService.class);
		contextService.deactivateContext(itsContext);
	}
}
